package com.bootcamp.javase;


import java.util.Scanner;

/**
 * @program: OopCode
 * @description: transfer a decimal into a Binary by resursion
 * @author: Keyu Li
 * @create: 2021-08-27 19:24
 **/

public class DecimalTransBinaryRecursive {
    public static void main(String[] args) {
        System.out.println("Please input an Integer no less than 0(-1 exit):");
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        while (num>=0){
            System.out.print("the binary form of "+num+" is:  ");
            transToBinary(num);
            System.out.println("\nPlease input an Integer no less than 0(-1 exit):");
            num = sc.nextInt();
        }
    }

    private static void transToBinary(int num) {
        if (num==1){
            System.out.print(1);
            return;
        }
        transToBinary(num/2);
        System.out.print(num%2);
    }
}
